.class public Lcom/zuiapps/suite/utils/process/PSHelper;
.super Ljava/lang/Object;
.source "PSHelper.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/zuiapps/suite/utils/process/PSHelper$DaemonCallback;
    }
.end annotation


# direct methods
.method public constructor <init>()V
    .registers 1

    .prologue
    .line 19
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 148
    return-void
.end method

.method public static getCurProcessName(Landroid/content/Context;)Ljava/lang/String;
    .registers 6
    .param p0, "context"    # Landroid/content/Context;

    .prologue
    .line 164
    invoke-static {}, Landroid/os/Process;->myPid()I

    move-result v2

    .line 165
    .local v2, "pid":I
    const-string v3, "activity"

    .line 166
    invoke-virtual {p0, v3}, Landroid/content/Context;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Landroid/app/ActivityManager;

    .line 168
    .local v1, "mActivityManager":Landroid/app/ActivityManager;
    invoke-virtual {v1}, Landroid/app/ActivityManager;->getRunningAppProcesses()Ljava/util/List;

    move-result-object v3

    .line 167
    invoke-interface {v3}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v3

    :cond_14
    invoke-interface {v3}, Ljava/util/Iterator;->hasNext()Z

    move-result v4

    if-eqz v4, :cond_27

    invoke-interface {v3}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/app/ActivityManager$RunningAppProcessInfo;

    .line 169
    .local v0, "appProcess":Landroid/app/ActivityManager$RunningAppProcessInfo;
    iget v4, v0, Landroid/app/ActivityManager$RunningAppProcessInfo;->pid:I

    if-ne v4, v2, :cond_14

    .line 171
    iget-object v3, v0, Landroid/app/ActivityManager$RunningAppProcessInfo;->processName:Ljava/lang/String;

    .line 174
    .end local v0    # "appProcess":Landroid/app/ActivityManager$RunningAppProcessInfo;
    :goto_26
    return-object v3

    :cond_27
    const-string v3, ""

    goto :goto_26
.end method

.method public static getPid(Ljava/lang/String;)Ljava/util/List;
    .registers 18
    .param p0, "pName"    # Ljava/lang/String;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/lang/String;",
            ")",
            "Ljava/util/List",
            "<",
            "Ljava/lang/Integer;",
            ">;"
        }
    .end annotation

    .prologue
    .line 34
    const/4 v6, 0x0

    .line 35
    .local v6, "line":Ljava/lang/String;
    const/4 v11, 0x0

    .line 36
    .local v11, "process":Ljava/lang/Process;
    const/4 v1, 0x0

    .line 37
    .local v1, "bufferedReader":Ljava/io/BufferedReader;
    const/16 v9, -0x64

    .line 39
    .local v9, "pidLocation":I
    new-instance v8, Ljava/util/ArrayList;

    invoke-direct {v8}, Ljava/util/ArrayList;-><init>()V

    .line 41
    .local v8, "pidList":Ljava/util/List;, "Ljava/util/List<Ljava/lang/Integer;>;"
    :try_start_a
    invoke-static {}, Ljava/lang/Runtime;->getRuntime()Ljava/lang/Runtime;

    move-result-object v15

    const-string v16, "ps"

    invoke-virtual/range {v15 .. v16}, Ljava/lang/Runtime;->exec(Ljava/lang/String;)Ljava/lang/Process;

    move-result-object v11

    .line 42
    new-instance v2, Ljava/io/BufferedReader;

    new-instance v15, Ljava/io/InputStreamReader;

    invoke-virtual {v11}, Ljava/lang/Process;->getInputStream()Ljava/io/InputStream;

    move-result-object v16

    invoke-direct/range {v15 .. v16}, Ljava/io/InputStreamReader;-><init>(Ljava/io/InputStream;)V

    invoke-direct {v2, v15}, Ljava/io/BufferedReader;-><init>(Ljava/io/Reader;)V
    :try_end_22
    .catch Ljava/lang/Throwable; {:try_start_a .. :try_end_22} :catch_8c
    .catchall {:try_start_a .. :try_end_22} :catchall_9d

    .line 43
    .end local v1    # "bufferedReader":Ljava/io/BufferedReader;
    .local v2, "bufferedReader":Ljava/io/BufferedReader;
    :try_start_22
    sget-object v15, Ljava/util/Locale;->ENGLISH:Ljava/util/Locale;

    move-object/from16 v0, p0

    invoke-virtual {v0, v15}, Ljava/lang/String;->toUpperCase(Ljava/util/Locale;)Ljava/lang/String;

    move-result-object v12

    .line 44
    .local v12, "processName":Ljava/lang/String;
    :cond_2a
    :goto_2a
    invoke-virtual {v2}, Ljava/io/BufferedReader;->readLine()Ljava/lang/String;

    move-result-object v6

    if-eqz v6, :cond_7b

    .line 45
    sget-object v15, Ljava/util/Locale;->ENGLISH:Ljava/util/Locale;

    invoke-virtual {v6, v15}, Ljava/lang/String;->toUpperCase(Ljava/util/Locale;)Ljava/lang/String;

    move-result-object v7

    .line 46
    .local v7, "lineTemp":Ljava/lang/String;
    const-string v15, "PID"

    invoke-virtual {v7, v15}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z

    move-result v15

    if-eqz v15, :cond_4d

    const-string v15, "PPID"

    invoke-virtual {v7, v15}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z

    move-result v15

    if-eqz v15, :cond_4d

    .line 47
    const-string v15, "PID"

    invoke-static {v7, v15}, Lcom/zuiapps/suite/utils/process/PSHelper;->getProcessLocation(Ljava/lang/String;Ljava/lang/String;)I

    move-result v9

    goto :goto_2a

    .line 48
    :cond_4d
    invoke-virtual {v7, v12}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z

    move-result v15

    if-eqz v15, :cond_2a

    .line 49
    new-instance v13, Ljava/util/StringTokenizer;

    const-string v15, " "

    const/16 v16, 0x0

    move/from16 v0, v16

    invoke-direct {v13, v7, v15, v0}, Ljava/util/StringTokenizer;-><init>(Ljava/lang/String;Ljava/lang/String;Z)V

    .line 50
    .local v13, "st":Ljava/util/StringTokenizer;
    if-ltz v9, :cond_2a

    .line 51
    const/4 v4, 0x0

    .local v4, "i":I
    invoke-virtual {v13}, Ljava/util/StringTokenizer;->countTokens()I

    move-result v5

    .local v5, "len":I
    :goto_65
    if-ge v4, v5, :cond_2a

    .line 52
    invoke-virtual {v13}, Ljava/util/StringTokenizer;->nextToken()Ljava/lang/String;

    move-result-object v10

    .line 53
    .local v10, "pidStr":Ljava/lang/String;
    if-ne v4, v9, :cond_78

    .line 54
    invoke-static {v10}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v15

    invoke-static {v15}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v15

    invoke-interface {v8, v15}, Ljava/util/List;->add(Ljava/lang/Object;)Z
    :try_end_78
    .catch Ljava/lang/Throwable; {:try_start_22 .. :try_end_78} :catch_b1
    .catchall {:try_start_22 .. :try_end_78} :catchall_ae

    .line 51
    :cond_78
    add-int/lit8 v4, v4, 0x1

    goto :goto_65

    .line 66
    .end local v4    # "i":I
    .end local v5    # "len":I
    .end local v7    # "lineTemp":Ljava/lang/String;
    .end local v10    # "pidStr":Ljava/lang/String;
    .end local v13    # "st":Ljava/util/StringTokenizer;
    :cond_7b
    if-eqz v2, :cond_80

    .line 67
    :try_start_7d
    invoke-virtual {v2}, Ljava/io/BufferedReader;->close()V
    :try_end_80
    .catch Ljava/io/IOException; {:try_start_7d .. :try_end_80} :catch_87

    .line 72
    :cond_80
    :goto_80
    if-eqz v11, :cond_85

    .line 73
    invoke-virtual {v11}, Ljava/lang/Process;->destroy()V

    :cond_85
    move-object v1, v2

    .end local v2    # "bufferedReader":Ljava/io/BufferedReader;
    .end local v12    # "processName":Ljava/lang/String;
    .restart local v1    # "bufferedReader":Ljava/io/BufferedReader;
    :cond_86
    :goto_86
    return-object v8

    .line 69
    .end local v1    # "bufferedReader":Ljava/io/BufferedReader;
    .restart local v2    # "bufferedReader":Ljava/io/BufferedReader;
    .restart local v12    # "processName":Ljava/lang/String;
    :catch_87
    move-exception v3

    .line 70
    .local v3, "e":Ljava/io/IOException;
    invoke-virtual {v3}, Ljava/io/IOException;->printStackTrace()V

    goto :goto_80

    .line 62
    .end local v2    # "bufferedReader":Ljava/io/BufferedReader;
    .end local v3    # "e":Ljava/io/IOException;
    .end local v12    # "processName":Ljava/lang/String;
    .restart local v1    # "bufferedReader":Ljava/io/BufferedReader;
    :catch_8c
    move-exception v14

    .line 66
    .local v14, "t":Ljava/lang/Throwable;
    :goto_8d
    if-eqz v1, :cond_92

    .line 67
    :try_start_8f
    invoke-virtual {v1}, Ljava/io/BufferedReader;->close()V
    :try_end_92
    .catch Ljava/io/IOException; {:try_start_8f .. :try_end_92} :catch_98

    .line 72
    :cond_92
    :goto_92
    if-eqz v11, :cond_86

    .line 73
    invoke-virtual {v11}, Ljava/lang/Process;->destroy()V

    goto :goto_86

    .line 69
    :catch_98
    move-exception v3

    .line 70
    .restart local v3    # "e":Ljava/io/IOException;
    invoke-virtual {v3}, Ljava/io/IOException;->printStackTrace()V

    goto :goto_92

    .line 65
    .end local v3    # "e":Ljava/io/IOException;
    .end local v14    # "t":Ljava/lang/Throwable;
    :catchall_9d
    move-exception v15

    .line 66
    :goto_9e
    if-eqz v1, :cond_a3

    .line 67
    :try_start_a0
    invoke-virtual {v1}, Ljava/io/BufferedReader;->close()V
    :try_end_a3
    .catch Ljava/io/IOException; {:try_start_a0 .. :try_end_a3} :catch_a9

    .line 72
    :cond_a3
    :goto_a3
    if-eqz v11, :cond_a8

    .line 73
    invoke-virtual {v11}, Ljava/lang/Process;->destroy()V

    :cond_a8
    throw v15

    .line 69
    :catch_a9
    move-exception v3

    .line 70
    .restart local v3    # "e":Ljava/io/IOException;
    invoke-virtual {v3}, Ljava/io/IOException;->printStackTrace()V

    goto :goto_a3

    .line 65
    .end local v1    # "bufferedReader":Ljava/io/BufferedReader;
    .end local v3    # "e":Ljava/io/IOException;
    .restart local v2    # "bufferedReader":Ljava/io/BufferedReader;
    :catchall_ae
    move-exception v15

    move-object v1, v2

    .end local v2    # "bufferedReader":Ljava/io/BufferedReader;
    .restart local v1    # "bufferedReader":Ljava/io/BufferedReader;
    goto :goto_9e

    .line 62
    .end local v1    # "bufferedReader":Ljava/io/BufferedReader;
    .restart local v2    # "bufferedReader":Ljava/io/BufferedReader;
    :catch_b1
    move-exception v14

    move-object v1, v2

    .end local v2    # "bufferedReader":Ljava/io/BufferedReader;
    .restart local v1    # "bufferedReader":Ljava/io/BufferedReader;
    goto :goto_8d
.end method

.method private static getProcessLocation(Ljava/lang/String;Ljava/lang/String;)I
    .registers 8
    .param p0, "line"    # Ljava/lang/String;
    .param p1, "key"    # Ljava/lang/String;

    .prologue
    .line 22
    new-instance v3, Ljava/util/StringTokenizer;

    const-string v4, " "

    const/4 v5, 0x0

    invoke-direct {v3, p0, v4, v5}, Ljava/util/StringTokenizer;-><init>(Ljava/lang/String;Ljava/lang/String;Z)V

    .line 23
    .local v3, "st":Ljava/util/StringTokenizer;
    new-instance v2, Ljava/util/LinkedHashMap;

    invoke-direct {v2}, Ljava/util/LinkedHashMap;-><init>()V

    .line 24
    .local v2, "processMap":Ljava/util/Map;, "Ljava/util/Map<Ljava/lang/String;Ljava/lang/Integer;>;"
    const/4 v0, 0x0

    .local v0, "i":I
    invoke-virtual {v3}, Ljava/util/StringTokenizer;->countTokens()I

    move-result v1

    .local v1, "len":I
    :goto_12
    if-ge v0, v1, :cond_22

    .line 25
    invoke-virtual {v3}, Ljava/util/StringTokenizer;->nextToken()Ljava/lang/String;

    move-result-object v4

    invoke-static {v0}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v5

    invoke-interface {v2, v4, v5}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 24
    add-int/lit8 v0, v0, 0x1

    goto :goto_12

    .line 27
    :cond_22
    invoke-interface {v2, p1}, Ljava/util/Map;->containsKey(Ljava/lang/Object;)Z

    move-result v4

    if-eqz v4, :cond_33

    .line 28
    invoke-interface {v2, p1}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v4

    check-cast v4, Ljava/lang/Integer;

    invoke-virtual {v4}, Ljava/lang/Integer;->intValue()I

    move-result v4

    .line 30
    :goto_32
    return v4

    :cond_33
    const/16 v4, -0x64

    goto :goto_32
.end method

.method public static isProcessRunning(Ljava/lang/String;Lcom/zuiapps/suite/utils/process/PSHelper$DaemonCallback;)V
    .registers 3
    .param p0, "pName"    # Ljava/lang/String;
    .param p1, "daemonCallback"    # Lcom/zuiapps/suite/utils/process/PSHelper$DaemonCallback;

    .prologue
    .line 79
    new-instance v0, Lcom/zuiapps/suite/utils/process/PSHelper$1;

    invoke-direct {v0, p0, p1}, Lcom/zuiapps/suite/utils/process/PSHelper$1;-><init>(Ljava/lang/String;Lcom/zuiapps/suite/utils/process/PSHelper$DaemonCallback;)V

    .line 112
    invoke-virtual {v0}, Lcom/zuiapps/suite/utils/process/PSHelper$1;->start()V

    .line 113
    return-void
.end method

.method public static isProcessRunning(Ljava/lang/String;)Z
    .registers 12
    .param p0, "pName"    # Ljava/lang/String;

    .prologue
    .line 116
    const/4 v8, 0x0

    .line 118
    .local v8, "ret":Z
    const-string v9, "(\\d+).+?\\s+[DNRSTZ]\\s+(.+)$"

    invoke-static {v9}, Ljava/util/regex/Pattern;->compile(Ljava/lang/String;)Ljava/util/regex/Pattern;

    move-result-object v5

    .line 119
    .local v5, "pidPattern":Ljava/util/regex/Pattern;
    new-instance v4, Ljava/util/HashMap;

    invoke-direct {v4}, Ljava/util/HashMap;-><init>()V

    .line 122
    .local v4, "pidNames":Ljava/util/Map;, "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;"
    :try_start_c
    invoke-static {}, Ljava/lang/Runtime;->getRuntime()Ljava/lang/Runtime;

    move-result-object v9

    const-string v10, "ps"

    invoke-virtual {v9, v10}, Ljava/lang/Runtime;->exec(Ljava/lang/String;)Ljava/lang/Process;

    move-result-object v6

    .line 123
    .local v6, "process":Ljava/lang/Process;
    new-instance v0, Ljava/io/BufferedReader;

    new-instance v9, Ljava/io/InputStreamReader;

    invoke-virtual {v6}, Ljava/lang/Process;->getInputStream()Ljava/io/InputStream;

    move-result-object v10

    invoke-direct {v9, v10}, Ljava/io/InputStreamReader;-><init>(Ljava/io/InputStream;)V

    invoke-direct {v0, v9}, Ljava/io/BufferedReader;-><init>(Ljava/io/Reader;)V

    .line 126
    .local v0, "bufferedReader":Ljava/io/BufferedReader;
    :cond_24
    :goto_24
    invoke-virtual {v0}, Ljava/io/BufferedReader;->readLine()Ljava/lang/String;

    move-result-object v1

    .local v1, "line":Ljava/lang/String;
    if-eqz v1, :cond_40

    .line 127
    invoke-virtual {v5, v1}, Ljava/util/regex/Pattern;->matcher(Ljava/lang/CharSequence;)Ljava/util/regex/Matcher;

    move-result-object v2

    .line 128
    .local v2, "matcher":Ljava/util/regex/Matcher;
    invoke-virtual {v2}, Ljava/util/regex/Matcher;->find()Z

    move-result v9

    if-eqz v9, :cond_24

    .line 129
    const/4 v9, 0x2

    invoke-virtual {v2, v9}, Ljava/util/regex/Matcher;->group(I)Ljava/lang/String;

    move-result-object v3

    .line 130
    .local v3, "name":Ljava/lang/String;
    const/4 v9, 0x0

    invoke-interface {v4, v3, v9}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    goto :goto_24

    .line 142
    .end local v0    # "bufferedReader":Ljava/io/BufferedReader;
    .end local v1    # "line":Ljava/lang/String;
    .end local v2    # "matcher":Ljava/util/regex/Matcher;
    .end local v3    # "name":Ljava/lang/String;
    .end local v6    # "process":Ljava/lang/Process;
    :catch_3e
    move-exception v9

    .line 145
    :goto_3f
    return v8

    .line 134
    .restart local v0    # "bufferedReader":Ljava/io/BufferedReader;
    .restart local v1    # "line":Ljava/lang/String;
    .restart local v6    # "process":Ljava/lang/Process;
    :cond_40
    move-object v7, p0

    .line 135
    .local v7, "processName":Ljava/lang/String;
    invoke-interface {v4, v7}, Ljava/util/Map;->containsKey(Ljava/lang/Object;)Z

    move-result v9

    if-nez v9, :cond_4f

    .line 136
    const/4 v8, 0x0

    .line 140
    :goto_48
    invoke-virtual {v0}, Ljava/io/BufferedReader;->close()V

    .line 141
    invoke-virtual {v6}, Ljava/lang/Process;->destroy()V
    :try_end_4e
    .catch Ljava/io/IOException; {:try_start_c .. :try_end_4e} :catch_3e

    goto :goto_3f

    .line 138
    :cond_4f
    const/4 v8, 0x1

    goto :goto_48
.end method

.method public static killPs(Ljava/lang/String;)V
    .registers 2
    .param p0, "processName"    # Ljava/lang/String;

    .prologue
    .line 159
    invoke-static {p0}, Lcom/zuiapps/suite/utils/process/PSHelper;->getPid(Ljava/lang/String;)Ljava/util/List;

    move-result-object v0

    .line 160
    .local v0, "pids":Ljava/util/List;, "Ljava/util/List<Ljava/lang/Integer;>;"
    invoke-static {v0}, Lcom/zuiapps/suite/utils/process/PSHelper;->killPs(Ljava/util/List;)V

    .line 161
    return-void
.end method

.method public static killPs(Ljava/util/List;)V
    .registers 4
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/List",
            "<",
            "Ljava/lang/Integer;",
            ">;)V"
        }
    .end annotation

    .prologue
    .line 153
    .local p0, "pids":Ljava/util/List;, "Ljava/util/List<Ljava/lang/Integer;>;"
    invoke-interface {p0}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v1

    :goto_4
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v2

    if-eqz v2, :cond_18

    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/Integer;

    .line 154
    .local v0, "integer":Ljava/lang/Integer;
    invoke-virtual {v0}, Ljava/lang/Integer;->intValue()I

    move-result v2

    invoke-static {v2}, Landroid/os/Process;->killProcess(I)V

    goto :goto_4

    .line 156
    .end local v0    # "integer":Ljava/lang/Integer;
    :cond_18
    return-void
.end method
